package com.student.health.config;

import com.student.health.utils.DTO.ProjectUrlConfig;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.api.impl.WxMpServiceImpl;
import me.chanjar.weixin.mp.config.WxMpConfigStorage;
import me.chanjar.weixin.mp.config.impl.WxMpDefaultConfigImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Author: xxx
 * @Date: 2024-04-03 14:06
 * @Description:
 * @Version 1.0
 */
@Configuration
public class WeChatConfig {
    @Autowired
    private ProjectUrlConfig projectUrlConfig;

    @Bean
    public WxMpService wxMpService(){
        WxMpServiceImpl wxMpService = new WxMpServiceImpl();
        wxMpService.setWxMpConfigStorage(wxMpConfigStorage());
        return wxMpService;
    }

    @Bean
    public WxMpConfigStorage wxMpConfigStorage(){
        WxMpDefaultConfigImpl wxMpDefaultConfig = new WxMpDefaultConfigImpl();
        wxMpDefaultConfig.setAppId(projectUrlConfig.getMpAppId());
        wxMpDefaultConfig.setSecret(projectUrlConfig.getMpAppSecret());
        wxMpDefaultConfig.setTemplateId(projectUrlConfig.getTemplateId());
        return wxMpDefaultConfig;
    }
}
